<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>C51单片机学习——lcd1602液晶屏 | XiaoZiYan</title><meta name="keywords" content="学习,STC51&quot;,单片机,LCD1602"><meta name="author" content="XiaoZiYan"><meta name="copyright" content="XiaoZiYan"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="学习STC51&quot;单片机lcd1602">
<meta property="og:type" content="article">
<meta property="og:title" content="C51单片机学习——lcd1602液晶屏">
<meta property="og:url" content="https://xiaoziyanxiaoludan.gitee.io/xiaoziyan/2019/10/09/C51%E5%8D%95%E7%89%87%E6%9C%BA%E5%AD%A6%E4%B9%A0%E2%80%94%E2%80%94lcd1602%E6%B6%B2%E6%99%B6%E5%B1%8F/index.html">
<meta property="og:site_name" content="XiaoZiYan">
<meta property="og:description" content="学习STC51&quot;单片机lcd1602">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://xiaoziyan.top/images/3fe2d4f7f8aa0e706e4d555656cb673a.jpeg">
<meta property="article:published_time" content="2019-10-09T12:12:02.000Z">
<meta property="article:modified_time" content="2022-11-03T10:19:45.414Z">
<meta property="article:author" content="XiaoZiYan">
<meta property="article:tag" content="学习">
<meta property="article:tag" content="STC51&quot;">
<meta property="article:tag" content="单片机">
<meta property="article:tag" content="LCD1602">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://xiaoziyan.top/images/3fe2d4f7f8aa0e706e4d555656cb673a.jpeg"><link rel="shortcut icon" href="/xiaoziyan/img/favicon.png"><link rel="canonical" href="https://xiaoziyanxiaoludan.gitee.io/xiaoziyan/2019/10/09/C51%E5%8D%95%E7%89%87%E6%9C%BA%E5%AD%A6%E4%B9%A0%E2%80%94%E2%80%94lcd1602%E6%B6%B2%E6%99%B6%E5%B1%8F/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><meta/><link rel="stylesheet" href="/xiaoziyan/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/xiaoziyan/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: {"limitCount":50,"languages":{"author":"作者: XiaoZiYan","link":"链接: ","source":"来源: XiaoZiYan","info":"著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。"}},
  lightbox: 'fancybox',
  Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#49b1f5","bgDark":"#121212","position":"bottom-left"},
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: true,
  islazyload: false,
  isanchor: true
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'C51单片机学习——lcd1602液晶屏',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2022-11-03 18:19:45'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if (GLOBAL_CONFIG_SITE.isHome && /iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><link rel="stylesheet" href="./css/custom.css" media="defer" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome/css/font-awesome.min.css"><!-- hexo injector head_end start --><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Zfour/hexo-electric-clock@1.0.6/clock.css"><!-- hexo injector head_end end --><meta name="generator" content="Hexo 5.4.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/xiaoziyan/img/avatar.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/xiaoziyan/archives/"><div class="headline">文章</div><div class="length-num">33</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/xiaoziyan/tags/"><div class="headline">标签</div><div class="length-num">41</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/xiaoziyan/categories/"><div class="headline">分类</div><div class="length-num">39</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/xiaoziyan/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/xiaoziyan/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/xiaoziyan/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/xiaoziyan/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 多媒体</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/xiaoziyan/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/xiaoziyan/movies/"><i class="fa-fw fas fa-video"></i><span> 视频</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/xiaoziyan/link/"><i class="fa-fw fas fa-link"></i><span> 友情链接</span></a></div><div class="menus_item"><a class="site-page" href="/xiaoziyan/about/"><i class="fa-fw fas fa-heart"></i><span> 关于我</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('http://xiaoziyan.top/images/3fe2d4f7f8aa0e706e4d555656cb673a.jpeg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/xiaoziyan/">XiaoZiYan</a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/xiaoziyan/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/xiaoziyan/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/xiaoziyan/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/xiaoziyan/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 多媒体</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/xiaoziyan/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/xiaoziyan/movies/"><i class="fa-fw fas fa-video"></i><span> 视频</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/xiaoziyan/link/"><i class="fa-fw fas fa-link"></i><span> 友情链接</span></a></div><div class="menus_item"><a class="site-page" href="/xiaoziyan/about/"><i class="fa-fw fas fa-heart"></i><span> 关于我</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">C51单片机学习——lcd1602液晶屏</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2019-10-09T12:12:02.000Z" title="发表于 2019-10-09 20:12:02">2019-10-09</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2022-11-03T10:19:45.414Z" title="更新于 2022-11-03 18:19:45">2022-11-03</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/xiaoziyan/categories/%E5%8D%95%E7%89%87%E6%9C%BA%E5%AD%A6%E4%B9%A0/">单片机学习</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/xiaoziyan/categories/%E5%8D%95%E7%89%87%E6%9C%BA%E5%AD%A6%E4%B9%A0/STC51/">STC51&quot;</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/xiaoziyan/categories/%E5%8D%95%E7%89%87%E6%9C%BA%E5%AD%A6%E4%B9%A0/STC51/%E5%8D%95%E7%89%87%E6%9C%BA/">单片机</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="C51单片机学习——lcd1602液晶屏"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h2 id="lcd1602液晶屏实验"><a href="#lcd1602液晶屏实验" class="headerlink" title="lcd1602液晶屏实验"></a>lcd1602液晶屏实验</h2><h3 id="实验目的"><a href="#实验目的" class="headerlink" title="实验目的"></a>实验目的</h3><ul>
<li>掌握AT89C51单片机的引脚功能</li>
<li>掌握AT89C51最小系统电路设计</li>
<li>掌握C语言基本构成和基本语句</li>
<li>掌握P0、P1、P2和P3功能及应用技能</li>
</ul>
<h3 id="实验原理与内容"><a href="#实验原理与内容" class="headerlink" title="实验原理与内容"></a>实验原理与内容</h3><blockquote>
<p>实现通过单片机控制1602显示屏显示自己的学号姓名，熟悉掌握编程软件keil及仿真软件Proteus，熟悉数组的使用及循环结构（while、for）基本用法。</p>
</blockquote>
<h3 id="实验软硬件环境"><a href="#实验软硬件环境" class="headerlink" title="实验软硬件环境"></a>实验软硬件环境</h3><p>硬件：PC一台、单片机试验箱</p>
<p>软件：keil5、proteus、单片机程序下载软件</p>
<h3 id="实验过程（实验步骤、记录、数据、分析）"><a href="#实验过程（实验步骤、记录、数据、分析）" class="headerlink" title="实验过程（实验步骤、记录、数据、分析）"></a>实验过程（实验步骤、记录、数据、分析）</h3><h4 id="根据需求画出仿真图"><a href="#根据需求画出仿真图" class="headerlink" title="根据需求画出仿真图"></a>根据需求画出仿真图</h4><p><img src="http://xiaoziyan.top/images/image-20211011085617250.png"></p>
<h4 id="在keil5新建该实验的工程"><a href="#在keil5新建该实验的工程" class="headerlink" title="在keil5新建该实验的工程"></a>在keil5新建该实验的工程</h4><p><img src="http://xiaoziyan.top/images/image-20211011085741377.png"></p>
<h4 id="给工程添加一个C语言文件并编写驱动程序"><a href="#给工程添加一个C语言文件并编写驱动程序" class="headerlink" title="给工程添加一个C语言文件并编写驱动程序"></a>给工程添加一个C语言文件并编写驱动程序</h4><p><img src="http://xiaoziyan.top/images/image-20211011085905463.png"></p>
<p><strong>驱动程序代码如下：</strong>     </p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;reg51.h&gt;</span></span></span><br><span class="line"><span class="keyword">unsigned</span> <span class="keyword">char</span> x[]=<span class="string">&quot;ZhengHuaZong&quot;</span>;</span><br><span class="line"><span class="keyword">unsigned</span> <span class="keyword">char</span> y[]=<span class="string">&quot;2018324418&quot;</span>;</span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> uchar unsigned char </span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> uint unsigned int</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">sbit LCD_RS = P3^<span class="number">0</span>;</span><br><span class="line">sbit LCD_RW = P3^<span class="number">1</span>;</span><br><span class="line">sbit LCD_E = P3^<span class="number">2</span>;</span><br><span class="line"></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> LCD_ch P1</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//延时函数</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">delay</span><span class="params">(uint i)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	<span class="keyword">while</span>(i--);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//lcd控制命令</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">LCD_command</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	LCD_RS = <span class="number">0</span>;</span><br><span class="line">	LCD_RW = <span class="number">0</span>;</span><br><span class="line">	LCD_E = <span class="number">0</span>;</span><br><span class="line">	delay(<span class="number">200</span>);</span><br><span class="line">	LCD_E = <span class="number">1</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//把数据写入lcd1602</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">LCD_data</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	LCD_RS= <span class="number">1</span>;</span><br><span class="line">	LCD_RW =<span class="number">0</span>;</span><br><span class="line">	LCD_E = <span class="number">0</span>;</span><br><span class="line">	delay(<span class="number">200</span>);</span><br><span class="line">	LCD_E=<span class="number">1</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">Init_LCD</span><span class="params">(<span class="keyword">void</span>)</span> <span class="comment">//初始化函数</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	LCD_ch = <span class="number">0x01</span>;    <span class="comment">//清屏</span></span><br><span class="line">	LCD_command();</span><br><span class="line">	LCD_ch = <span class="number">0x38</span>;    <span class="comment">//8位数据，两行显示、5x7点阵</span></span><br><span class="line">	LCD_command();</span><br><span class="line">	LCD_ch = <span class="number">0x0c</span>;    <span class="comment">//开显示，关光标</span></span><br><span class="line">	LCD_command();</span><br><span class="line">	LCD_ch = <span class="number">0x06</span>;    <span class="comment">//读写数据后AC自动增加一行，画面不动</span></span><br><span class="line">	LCD_command();</span><br><span class="line">	</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">LCD_dis</span><span class="params">(uchar i,uchar j,uchar ch)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	uchar addr;</span><br><span class="line">	<span class="keyword">if</span>(i==<span class="number">0</span>)addr = <span class="number">0x80</span>+j;   <span class="comment">//设置第一行</span></span><br><span class="line">	<span class="keyword">else</span> addr = <span class="number">0xc0</span> +j;      <span class="comment">//设置第二行</span></span><br><span class="line">	LCD_ch=addr;</span><br><span class="line">	LCD_command();</span><br><span class="line">	LCD_ch=ch;</span><br><span class="line">	LCD_data();       <span class="comment">//发送数据</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	<span class="keyword">unsigned</span> <span class="keyword">int</span> i,j;</span><br><span class="line">	Init_LCD();   <span class="comment">//初始化LCD显示屏</span></span><br><span class="line">	<span class="keyword">while</span>(<span class="number">1</span>)</span><br><span class="line">	&#123;</span><br><span class="line">		<span class="keyword">for</span>(i=<span class="number">0</span>;i&lt;<span class="number">12</span>;i++)</span><br><span class="line">		&#123;</span><br><span class="line">			<span class="comment">//LCD_dis(1,i,0x30+i)    // LCD_dis(0,i,i+&#x27;0&#x27;);   LCD_dis(1,i,i+&#x27;A&#x27;)</span></span><br><span class="line">			LCD_dis(<span class="number">1</span>,i,x[i]);   <span class="comment">//显示内容</span></span><br><span class="line">			delay(<span class="number">5000</span>);</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">for</span>(j=<span class="number">0</span>;j&lt;<span class="number">10</span>;j++)</span><br><span class="line">		&#123;</span><br><span class="line">			LCD_dis(<span class="number">0</span>,j,y[j]);</span><br><span class="line">			delay(<span class="number">5000</span>);</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;	</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="将编写好的驱动程序代码编译成16进制文件"><a href="#将编写好的驱动程序代码编译成16进制文件" class="headerlink" title="将编写好的驱动程序代码编译成16进制文件"></a>将编写好的驱动程序代码编译成16进制文件</h4><p> <img src="http://xiaoziyan.top/images/image-20211011085842757.png"></p>
<h4 id="将编译好的16进制文件导入到仿真环境中"><a href="#将编译好的16进制文件导入到仿真环境中" class="headerlink" title="将编译好的16进制文件导入到仿真环境中"></a>将编译好的16进制文件导入到仿真环境中</h4><p> <img src="http://xiaoziyan.top/images/image-20211011085930781.png"></p>
<h4 id="仿真环境功能实现"><a href="#仿真环境功能实现" class="headerlink" title="仿真环境功能实现"></a>仿真环境功能实现</h4><p> <img src="http://xiaoziyan.top/images/image-20211011085954451.png"></p>
<p><strong>6、将在仿真环境测试好的驱动文件下载进试验箱的单片机，接好单片机的线、效果如下：</strong></p>
<p><img src="http://xiaoziyan.top/images/image-20211011090006909.png"></p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">XiaoZiYan</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a target="_blank" rel="noopener" href="https://baidu.com">https://baidu.com</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://xiaoziyanxiaoludan.gitee.io/xiaoziyan" target="_blank">XiaoZiYan</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/xiaoziyan/tags/%E5%AD%A6%E4%B9%A0/">学习</a><a class="post-meta__tags" href="/xiaoziyan/tags/STC51/">STC51&quot;</a><a class="post-meta__tags" href="/xiaoziyan/tags/%E5%8D%95%E7%89%87%E6%9C%BA/">单片机</a><a class="post-meta__tags" href="/xiaoziyan/tags/LCD1602/">LCD1602</a></div><div class="post_share"><div class="social-share" data-image="http://xiaoziyan.top/images/3fe2d4f7f8aa0e706e4d555656cb673a.jpeg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/xiaoziyan/2019/10/11/C51%E5%8D%95%E7%89%87%E6%9C%BA%E5%AD%A6%E4%B9%A0%E2%80%94%E2%80%94%E5%A4%96%E9%83%A8%E4%B8%AD%E6%96%AD/"><img class="prev-cover" src="http://xiaoziyan.top/images/ac104f60351a347c48895f896bc64220.jpeg" onerror="onerror=null;src='/xiaoziyan/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">C51单片机学习——外部中断</div></div></a></div><div class="next-post pull-right"><a href="/xiaoziyan/2019/10/08/C51%E5%8D%95%E7%89%87%E6%9C%BA%E5%AD%A6%E4%B9%A0%E2%80%94%E2%80%94%E6%8C%89%E9%94%AE%E6%8E%A7%E5%88%B6/"><img class="next-cover" src="http://xiaoziyan.top/images/84c58abc41610ee19e1a478f91088e69.jpeg" onerror="onerror=null;src='/xiaoziyan/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">C51单片机学习——按键控制</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/xiaoziyan/2019/10/14/C51%E5%8D%95%E7%89%87%E6%9C%BA%E5%AD%A6%E4%B9%A0%E2%80%94%E2%80%94ADC%E3%80%81PWM/" title="C51单片机学习——ADC/PWM"><img class="cover" src="http://xiaoziyan.top/images/f45614980b681dfbe655f12e7ba148cd.jpeg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-10-14</div><div class="title">C51单片机学习——ADC/PWM</div></div></a></div><div><a href="/xiaoziyan/2019/10/11/C51%E5%8D%95%E7%89%87%E6%9C%BA%E5%AD%A6%E4%B9%A0%E2%80%94%E2%80%94%E5%A4%96%E9%83%A8%E4%B8%AD%E6%96%AD/" title="C51单片机学习——外部中断"><img class="cover" src="http://xiaoziyan.top/images/ac104f60351a347c48895f896bc64220.jpeg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-10-11</div><div class="title">C51单片机学习——外部中断</div></div></a></div><div><a href="/xiaoziyan/2019/10/08/C51%E5%8D%95%E7%89%87%E6%9C%BA%E5%AD%A6%E4%B9%A0%E2%80%94%E2%80%94%E6%8C%89%E9%94%AE%E6%8E%A7%E5%88%B6/" title="C51单片机学习——按键控制"><img class="cover" src="http://xiaoziyan.top/images/84c58abc41610ee19e1a478f91088e69.jpeg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-10-08</div><div class="title">C51单片机学习——按键控制</div></div></a></div><div><a href="/xiaoziyan/2019/10/06/C51%E5%8D%95%E7%89%87%E6%9C%BA%E5%AD%A6%E4%B9%A0%E2%80%94%E2%80%94%E6%B5%81%E6%B0%B4%E7%81%AF/" title="C51单片机学习——流水灯"><img class="cover" src="http://xiaoziyan.top/images/adb7f9eca04e6f962fe5f3e4a54d1d12.jpeg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-10-06</div><div class="title">C51单片机学习——流水灯</div></div></a></div><div><a href="/xiaoziyan/2019/10/13/C51%E5%8D%95%E7%89%87%E6%9C%BA%E5%AD%A6%E4%B9%A0%E2%80%94%E2%80%94%E8%AE%A1%E6%97%B6%E5%99%A8/" title="C51单片机学习——计时器"><img class="cover" src="http://xiaoziyan.top/images/993aef2c4e09cec3a090ec3a703eaa04.jpeg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-10-13</div><div class="title">C51单片机学习——计时器</div></div></a></div><div><a href="/xiaoziyan/2019/11/10/STM32%E5%AD%A6%E4%B9%A0%E2%80%94%E2%80%94%E5%88%9D%E8%AF%86stm32/" title="STM32学习——看门狗"><img class="cover" src="http://xiaoziyan.top/images/dog1.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-11-10</div><div class="title">STM32学习——看门狗</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#lcd1602%E6%B6%B2%E6%99%B6%E5%B1%8F%E5%AE%9E%E9%AA%8C"><span class="toc-number">1.</span> <span class="toc-text">lcd1602液晶屏实验</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%AE%9E%E9%AA%8C%E7%9B%AE%E7%9A%84"><span class="toc-number">1.1.</span> <span class="toc-text">实验目的</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%AE%9E%E9%AA%8C%E5%8E%9F%E7%90%86%E4%B8%8E%E5%86%85%E5%AE%B9"><span class="toc-number">1.2.</span> <span class="toc-text">实验原理与内容</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%AE%9E%E9%AA%8C%E8%BD%AF%E7%A1%AC%E4%BB%B6%E7%8E%AF%E5%A2%83"><span class="toc-number">1.3.</span> <span class="toc-text">实验软硬件环境</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%AE%9E%E9%AA%8C%E8%BF%87%E7%A8%8B%EF%BC%88%E5%AE%9E%E9%AA%8C%E6%AD%A5%E9%AA%A4%E3%80%81%E8%AE%B0%E5%BD%95%E3%80%81%E6%95%B0%E6%8D%AE%E3%80%81%E5%88%86%E6%9E%90%EF%BC%89"><span class="toc-number">1.4.</span> <span class="toc-text">实验过程（实验步骤、记录、数据、分析）</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%A0%B9%E6%8D%AE%E9%9C%80%E6%B1%82%E7%94%BB%E5%87%BA%E4%BB%BF%E7%9C%9F%E5%9B%BE"><span class="toc-number">1.4.1.</span> <span class="toc-text">根据需求画出仿真图</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%9C%A8keil5%E6%96%B0%E5%BB%BA%E8%AF%A5%E5%AE%9E%E9%AA%8C%E7%9A%84%E5%B7%A5%E7%A8%8B"><span class="toc-number">1.4.2.</span> <span class="toc-text">在keil5新建该实验的工程</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E7%BB%99%E5%B7%A5%E7%A8%8B%E6%B7%BB%E5%8A%A0%E4%B8%80%E4%B8%AAC%E8%AF%AD%E8%A8%80%E6%96%87%E4%BB%B6%E5%B9%B6%E7%BC%96%E5%86%99%E9%A9%B1%E5%8A%A8%E7%A8%8B%E5%BA%8F"><span class="toc-number">1.4.3.</span> <span class="toc-text">给工程添加一个C语言文件并编写驱动程序</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%B0%86%E7%BC%96%E5%86%99%E5%A5%BD%E7%9A%84%E9%A9%B1%E5%8A%A8%E7%A8%8B%E5%BA%8F%E4%BB%A3%E7%A0%81%E7%BC%96%E8%AF%91%E6%88%9016%E8%BF%9B%E5%88%B6%E6%96%87%E4%BB%B6"><span class="toc-number">1.4.4.</span> <span class="toc-text">将编写好的驱动程序代码编译成16进制文件</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%B0%86%E7%BC%96%E8%AF%91%E5%A5%BD%E7%9A%8416%E8%BF%9B%E5%88%B6%E6%96%87%E4%BB%B6%E5%AF%BC%E5%85%A5%E5%88%B0%E4%BB%BF%E7%9C%9F%E7%8E%AF%E5%A2%83%E4%B8%AD"><span class="toc-number">1.4.5.</span> <span class="toc-text">将编译好的16进制文件导入到仿真环境中</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%BB%BF%E7%9C%9F%E7%8E%AF%E5%A2%83%E5%8A%9F%E8%83%BD%E5%AE%9E%E7%8E%B0"><span class="toc-number">1.4.6.</span> <span class="toc-text">仿真环境功能实现</span></a></li></ol></li></ol></li></ol></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2022 By XiaoZiYan</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div><div class="footer_custom_text"><p><a style="margin-inline:5px"target="_blank" href="https://hexo.io/"> <img src="https://img.shields.io/badge/Frame-Hexo-blue?style=flat&logo=hexo" title="博客框架为 Hexo" alt="HEXO"></a><a style="margin-inline:5px"target="_blank"href="https://butterfly.js.org/"> <img src="https://img.shields.io/badge/Theme-Butterfly-6513df?style=flat&logo=bitdefender" title="主题采用 Butterfly" alt="Butterfly"></a><a style="margin-inline:5px"target="_blank" href="https://www.jsdelivr.com/"> <img src="https://img.shields.io/badge/CDN-jsDelivr-orange?style=flat&logo=jsDelivr" title="本站使用 Jsdelivr 为静态资源提供CDN加速" alt="Jsdelivr"></a><a style="margin-inline:5px"target="_blank" href="https://github.com/"> <img src="https://img.shields.io/badge/Source-gitee-d021d6?style=flat&logo=Gitee" title="本站项目由 Gitee 托管" alt="Gitee"></a><a style="margin-inline:5px"target="_blank"href="http://creativecommons.org/licenses/by-nc-sa/4.0/"> <img src="https://img.shields.io/badge/Copyright-BY--NC--SA%204.0-d42328?style=flat&logo=Claris" alt="img" title="本站采用知识共享署名-非商业性使用-相同方式共享4.0国际许可协议进行许可"></a></p></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/xiaoziyan/js/utils.js"></script><script src="/xiaoziyan/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/instant.page/instantpage.min.js" type="module"></script><script src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><script>function panguFn () {
  if (typeof pangu === 'object') pangu.autoSpacingPage()
  else {
    getScript('https://cdn.jsdelivr.net/npm/pangu/dist/browser/pangu.min.js')
      .then(() => {
        pangu.autoSpacingPage()
      })
  }
}

function panguInit () {
  if (false){
    GLOBAL_CONFIG_SITE.isPost && panguFn()
  } else {
    panguFn()
  }
}

document.addEventListener('DOMContentLoaded', panguInit)</script><script>var preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',preloader.endLoading())</script><div class="js-pjax"></div><script src="./js/sakura.js"></script><canvas class="fireworks" mobile="false"></canvas><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/fireworks.min.js"></script><script defer="defer" id="ribbon" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-ribbon.min.js" size="150" alpha="0.6" zIndex="-1" mobile="false" data-click="true"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><!-- hexo injector body_end start --><script data-pjax>function electric_clock_injector_config(){
                var parent_div_git = document.getElementsByClassName('sticky_layout')[0];
                var item_html = '<div class="card-widget card-clock"><div class="card-glass"><div class="card-background"><div class="card-content"><div id="hexo_electric_clock"><img id="card-clock-loading" src="https://cdn.jsdelivr.net/gh/Zfour/Butterfly-clock/clock/images/weather/loading.gif" style="height: 120px; width: 100%;" data-ll-status="loading" class="entered loading"></div></div></div></div></div>';
                console.log('已挂载electric_clock')
                // parent_div_git.innerHTML=item_html+parent_div_git.innerHTML // 无报错，但不影响使用(支持pjax跳转)
                parent_div_git.insertAdjacentHTML("afterbegin",item_html) // 有报错，但不影响使用(支持pjax跳转)
            }if( document.getElementsByClassName('sticky_layout')[0] && (location.pathname ==='all'|| 'all' ==='all')){

            electric_clock_injector_config()
        } </script><script src="https://pv.sohu.com/cityjson?ie=utf-8"></script><script data-pjax  src="https://cdn.jsdelivr.net/gh/Zfour/hexo-electric-clock@1.0.6/clock.js"></script><!-- hexo injector body_end end --></body></html>